/*
 * 存放一些基础的公用的函数，方法
 * 
 */

/* 实时获取最新js,css文件的方法*/
// Check if a new cache is available on page load.
window.addEventListener('load', function(e) {
  window.applicationCache.addEventListener('updateready', function(e) {
    if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
      // Browser downloaded a new app cache.
      // Swap it in and reload the page to get the new hotness.
      window.applicationCache.swapCache();
      window.location.reload();
    } else {
      // Manifest didn't changed. Nothing new to server.
    }
  }, false);
}, false);

function loadJsRender(name, path) {
	var renderer = $.render[name];
	if (renderer == null) {
		$.ajax({
			url : path,
			dataType : "text",
			async : false,
			success : function(data) {
				var temp = [];
				temp[name] = data;
				$.templates(temp);
				renderer = $.render[name];
			}
		});
		return renderer;
	}
	return renderer;
}


function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg); //匹配目标参数
	if (r != null)
		return unescape(r[2]);
	return null; //返回参数值
}